package hcontroller

import (
	"encoding/json"

	"advertoper/controllers"
	"advertoper/errorcode"
	"advertoper/homepageinfo/hservice"
)

type ZJPageViewInfoController struct {
	controllers.SCLoginedController
}

/*添加PageView图片
{"region_code":"all","clickable":1,"title":"热门","title_id":6,
"starttick":1,"endtick":1499999999,"routers":"zhjt://app.zjdj.com/goodslist"}
*/
// @router /pageview/add [post]
func (p *ZJPageViewInfoController) PageViewAdd() {
	defer p.Output("PageViewAdd")
	p.ForceHTTPS()

	body := p.Ctx.Input.RequestBody
	req := &hservice.ZJPageViewAdd{}
	if err := json.Unmarshal(body, req); err != nil {
		p.Resp["code"] = errorcode.EC_GL_INVALID_JSON_BODY
		p.Resp["msg"] = errorcode.Msg(errorcode.EC_GL_INVALID_JSON_BODY)
		return
	}
	code, msg := hservice.GetZJPageViewInfoService().PageViewAdd(req)
	p.Resp["code"] = code
	p.Resp["msg"] = msg

}

/*修改PageView图片
{"id":1,"region_code":"all","clickable":1,"title":"热门","title_id":6,
"starttick":1,"endtick":1499999999,"routers":"zhjt://app.zjdj.com/goodslist"}
*/
// @router /pageview/update [post]
func (p *ZJPageViewInfoController) PageViewUpdate() {
	defer p.Output("PageViewUpdate")
	p.ForceHTTPS()

	body := p.Ctx.Input.RequestBody
	req := &hservice.ZJPageViewUpdate{}
	if err := json.Unmarshal(body, req); err != nil {
		p.Resp["code"] = errorcode.EC_GL_INVALID_JSON_BODY
		p.Resp["msg"] = errorcode.Msg(errorcode.EC_GL_INVALID_JSON_BODY)
		return
	}
	code, msg := hservice.GetZJPageViewInfoService().PageViewUpdate(req)
	p.Resp["code"] = code
	p.Resp["msg"] = msg

}

//web查询
// @router /pageview/list [get]
func (p *ZJPageViewInfoController) PageViewList() {
	defer p.Output("PageViewList")
	p.ForceHTTPS()

	status, _ := p.GetInt("status", 1)
	data := hservice.GetZJPageViewInfoService().PageViewList(status)
	if len(data) == 0 {
		p.Resp["code"] = 101
		p.Resp["msg"] = "no data"
	} else {
		p.Resp["code"] = 0
		p.Resp["msg"] = "success"
		p.Resp["data"] = data
	}

}
